package com.everyday.practice.leetCode;

public class Title198 {

    public static void main(String[] args) {
        int[] arr=new int[4];
        arr[0]=2;
        arr[1]=7;
        arr[2]=9;
        arr[3]=3;
    System.out.println(max(arr));
    }

    public static int max(int[] arr){
        if (arr.length==0){
            return 0;
        }
        if (arr.length<=1){
            return arr[0];
        }
        int min0=arr[0];
        int min1=Math.max(arr[0],arr[1]);
        int temp=0;
        for (int i=2;i<arr.length;i++){
            temp=Math.max(min0+arr[i],min1);
            min0=min1;
            min1=temp;
        }
        return temp;
    }

//    1 2 3
}
